
/*
	Author: Genesis

	Description:
		Firing unsuppressed shots reveals unit.

	Parameter(s):
		0: OBJECT - Unit that fired
		1: STRING - Weapon fired
		2: STRING - Muzzle used
		3: STRING - Firing mode
		4: STRING - Ammo used
		5: STRING - Magazine used
		6: OBJECT - Projectile created
		7: OBJECT - Gunner whose weapon was fired (For use with vehicles)

	Returns:
		NOTHING
		
	Note:
		For use with "Fired" eventhandler
		
	Example1:
		this addEventHandler ["Fired", {
			_this call VCM_fnc_HearingAids;
		}];
		//edit by略游
		//此文件应该服务器执行，因为as_ai_groups变量，客户端不知道
*/

params ["_unit","_weapon","_muzzle","_mode","_ammo","_magazine","_bullet","_gunner"];

if (_weapon isEqualTo "Put" || {_weapon isEqualTo "Throw"}) exitwith {};

private _timeShot = _unit getVariable ["as_vcm_fth",-60];


//30秒触发一次
if ((_timeShot + 30) < time) then 
{
	//检查没有有消音器
	private _mzl = currentMuzzle _unit;
	private _mzl = if (_mzl isEqualType "") then {_mzl} else {""};
	private _atch = _unit weaponAccessories _mzl param [0, ""];
	private _return = (!(_atch isEqualTo "")) && {getNumber(configFile >> "CfgWeapons" >> _atch >> "ItemInfo" >> "AmmoCoef" >> "audibleFire") < 1};
	
	if (Param_Debug == 1) then {systemchat (format ["%2: WEAPON SUPRRESSED - %1",_return,_unit])};
	
	//systemchat format ["%1",_sup];
	_unit setVariable ["as_vcm_fth",time];
	
	if !(_return) then 
	{
		{
			if(!isNull _x && {count units _x >= 5})then
			{
				private _dis = (leader _x) distance _unit;
				if(_dis > 200 && {_dis < Param_EnemyEar})then
				{
					if (Param_Debug == 1) then {systemchat "一队AI被玩家吸引了注意力";_x setGroupIconParams [[1,0,0,1],"追踪",1,true];};
					
					//取消进驻建筑状态
					units _x doFollow leader _x;
					
					//从左侧包围
					//跟踪
					while {(count (waypoints _x)) > 0} do
					{
						deleteWaypoint ((waypoints _x) select 0);
					};
					private _pos_left = (position _unit) getPos [150 + random 180, ((leader _x) getDir _unit) + 90];
					[_x, _pos_left] call fn_addWaypoint;
					_x setBehaviour "AWARE";
					_x setFormation "ECH LEFT";
					_x setSpeedMode "FULL";
					
					
					if(Param_Debug == 1) then
					{
						private _marker = createMarker [format["marker_wp_%1", as_waypoint_cur], _pos_left];
						_marker setMarkerShape "ICON";
						_marker setMarkerColor "ColorRed";
						_marker setMarkerType "mil_arrow";
						_marker setMarkerText "包抄";
						as_waypoint_cur = as_waypoint_cur + 1;
					};
				};
			};
		}forEach as_ai_groups;	
	};
};



